package cn.com.demo.poi;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

public class ReadExcelFile {
    public static void main(String[] args) {
        try {
            // Create a FileInputStream to read the Excel file
            FileInputStream file = new FileInputStream(new File(""));

            // Create a Workbook object to access the Excel file
            Workbook workbook = WorkbookFactory.create(file);

            // Get the first sheet from the workbook
            Sheet sheet = workbook.getSheetAt(0);

            // Iterate through each row of the sheet
            for (Row row : sheet) {
                // Iterate through each cell of the row
                for (Cell cell : row) {
                    // Print the cell value
                    System.out.print(cell.getStringCellValue() + "\t");
                }
                System.out.println();
            }

            // Close the workbook and FileInputStream
            workbook.close();
            file.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}